<template>
	<view class="page-view">
		  <view class="top-bg">
			  <u-sticky>
		  	<view class="return" @click="goToBack()">
		  		<u-icon name="arrow-left" color="#ffffff " bold="true" size="38"></u-icon>
		  	</view>	
				有限空间作业
			</u-sticky>
		  </view> 
			<view class="posBox" :style="{ height: 'calc(100vh - 392rpx)' }">
				<scroll-view scroll-y="true" class="scroll-Y">
				<view class="uni-body" >
					<view class="flexItem" style="border: 0;"><view class="textName">申报日期</view><view class="text">{{dailyData.approvalDate | filterDate2}}</view></view>
					<view class="flexItem"><view class="textName">作业编号</view><view class="text">{{dailyData.workNo}}</view></view>
								<view class="flexItem"><view class="textName">作业内容</view><view class="text">{{dailyData.workDetail}}</view></view>
								<view class="flexItem"><view class="textName">作业位置</view><view class="text">{{dailyData.workArea}}</view></view>
					<view class="flexItem"><view class="textName">主要危险源</view><view class="text">{{dailyData.dangerSource||''}}</view>
					</view>
					<view class="flexItem"><view class="textName">作业风险等级</view><view class="text">{{dailyData.riskLevel==1?'高风险':'一般风险'}}</view>
					</view>
					<view class="flexItem"><view class="textName">作业单位名称</view><view class="text">{{dailyData.workUnit||''}}</view>
					</view>
					<view class="flexItem"><view class="textName">作业单位地址</view><view class="text">{{dailyData.workUnitPosition||''}}</view>
					</view>
					<view class="flexItem"><view class="textName">作业联系人</view><view class="text">{{dailyData.workContact||''}}</view>
					</view>
					<view class="flexItem"><view class="textName">联系人电话</view><view class="text">{{ dailyData.contactTel||'' }}</view>
					</view>
								<view class="note-red">
									<view class="" style="margin-top: 4rpx;"><image class="img" src=".././../static/icon/note-red.png" mode=""></image></view>
									是否经安全培训或岗前培训
									</view>
					<view class="flexItem"><view class="textName">现场作业负责人</view>
								<view class="text2">{{ dailyData.siteManager||'' }}</view>
								<u-icon v-if="dailyData.siteManagerStatus==1" name="checkmark-circle-fill" color="#0be583" size="30"></u-icon>
								<u-icon v-else name="close-circle" size="30"></u-icon>
					</view>
								<view class="flexItem"><view class="textName">监护人员</view>
								<view class="text2">{{ dailyData.siteGuardian||'' }}</view>
								<u-icon v-if="dailyData.siteGuardianStatus==1" name="checkmark-circle-fill" color="#0be583" size="30"></u-icon>
								<u-icon v-else name="close-circle" size="30"></u-icon>
								</view>
								<view class="flexItem"><view class="textName">作业人员</view>
								<view class="text2">{{ dailyData.siteWorker||'' }}</view>
								<u-icon v-if="dailyData.siteWorkerStatus==1" name="checkmark-circle-fill" color="#0be583" size="30"></u-icon>
								<u-icon v-else name="close-circle" size="30"></u-icon>
								</view>
								<view class="flexItem"><view class="textName">监管人员</view>
								<view class="text2">{{ dailyData.siteSupervisor||'' }}</view>
								<u-icon v-if="dailyData.siteSupervisorStatus==1" name="checkmark-circle-fill" color="#0be583" size="30"></u-icon>
								<u-icon v-else name="close-circle" size="30"></u-icon>
								</view>
								<view class="flexItem"><view class="textName">计划作业时间</view>
								<view class="text">{{ dailyData.planWorkDateBegin|filterDate}}至{{ dailyData.planWorkDateEnd|filterDate}}</view>
								</view>
								<view class="title">
									<view class="line-left"></view>所附材料上传
								</view>
					<view class="flexItem" style="border-bottom: 0;padding-bottom: 0"><view class="textName">安全交底资料</view>
						<!-- <view v-if="dailyData.safetyBriefingFile"> -->
								<view class="text" style="color: #3C8AFF;" @click="previewWechat(JSON.parse(dailyData.safetyBriefingFile || '{}').path)">
									{{JSON.parse(dailyData.safetyBriefingFile || '{}').name}}
									</view>
						<!-- </view> -->
					</view>
								<view class="flexItem" style="border-bottom: 0;padding-bottom: 0"><view class="textName">培训资料</view>
									<!-- <view v-if="dailyData.trainingFile"> -->
											<view class="text" style="color: #3C8AFF;" @click="previewWechat(JSON.parse(dailyData.trainingFile || '{}').path)">
												{{JSON.parse(dailyData.trainingFile || '{}').name}}
												</view>
									<!-- </view> -->
								</view>
								<view class="flexItem" style="border-bottom: 0;padding-bottom: 0"><view class="textName">器材机具清单</view>
									<!-- <view v-if="dailyData.equListFile"> -->
											<view class="text" style="color: #3C8AFF;" @click="previewWechat(JSON.parse(dailyData.equListFile || '{}').path)">
												{{JSON.parse(dailyData.equListFile || '{}').name}}
												</view>
									<!-- </view> -->
								</view>
								<view class="flexItem" style="border-bottom: 0;padding-bottom: 0"><view class="textName">作业方案</view>
									<!-- <view v-if="dailyData.workFile"> -->
											<view class="text" style="color: #3C8AFF;" @click="previewWechat(JSON.parse(dailyData.workFile || '{}').path)">
												{{JSON.parse(dailyData.workFile || '{}').name}}
												</view>
									<!-- </view> -->
								</view>
								<view class="flexItem" style="border-bottom: 0;padding-bottom: 0"><view class="textName">应急救援预案</view>
									<!-- <view v-if="dailyData.rescueFile"> -->
											<view class="text" style="color: #3C8AFF;" @click="previewWechat(JSON.parse(dailyData.rescueFile || '{}').path)">
												{{JSON.parse(dailyData.rescueFile || '{}').name}}
												</view>
									<!-- </view> -->
								</view>
								<view class="flexItem" style="border-bottom: 0;padding-bottom: 0"><view class="textName">其他资料</view>
									<!-- <view v-if="dailyData.otherFile"> -->
											<view v-if="dailyData.otherFile" class="text" style="color: #3C8AFF;" @click="previewWechat(JSON.parse(dailyData.otherFile || '{}').path)">
												{{JSON.parse(dailyData.otherFile || '{}').name}}
												</view>
									<!-- </view> -->
								</view>
								<view class="flexItem"><view class="textName">作业单位意见</view><view class="text">同意</view>
								</view>
								<view class="flexItem" ><view class="textName">意见提交时间</view><view class="text">{{dailyData.createTime|filterDate2}}</view>
								</view>
								<view class="" v-if="dailyData.status!==1">
									<view class="flexItem"><view class="textName">管理单位意见</view><view class="text">{{dailyData.approvalComments}}</view>
									</view>
									<view class="flexItem" ><view class="textName">意见提交时间</view><view class="text">{{dailyData.approvalPassDate|filterDate2}}</view>
									</view>
									<view class="flexItem" style="margin-bottom: 0;"><view class="textName">审批人员</view><view class="text">{{dailyData.approver||''}}</view>
									</view>
								</view>
								
				</view>
				<view class="uni-body info-row" v-if="dailyData.status==1"><text>管理单位意见</text>
				  <u--textarea placeholder="请输入审批意见" v-model="approvalComments" height="90"></u--textarea>
				</view>
				</scroll-view>
				<view class="btnBox" v-if="dailyData.status==1">
					<view class="btn-item" @click="disallowedFn()">驳回</view>
					 <view class="btn-item" style="color: #fff;background: #2769f7;" @click="approveFn()">同意</view>
					</view>
			</view>
			
	</view>
</template>
<script>
	import {getConfinedSpaceDetail} from '@/api/spaceWork.js';
	export default {
		filters: {
		  filterDate(dateStr) {
		    if (dateStr) {
		      dateStr = dateStr.replaceAll('-', '/');
		      return new Date(dateStr).format('yyyy-MM-dd hh');
		    } else {
		      return '';
		    }
		  },
		  filterDate2(dateStr) {
		    if (dateStr) {
		      dateStr = dateStr.replaceAll('-', '/');
		      return new Date(dateStr).format('yyyy-MM-dd');
		    } else {
		      return '';
		    }
		  }
		},
		data() {
			return {
				id:'',
				dailyData:{},
				approvalComments:'',
				maxDate: new Date().format('yyyy-MM-dd'),
			};
		},
		created() {

		},
		mounted() {},
		onLoad(options) {
		  this.id=options.id
		  this.getConfinedSpaceDetail()
			},
		methods: {
			goToBack(){
			  wx.navigateBack({
			      delta: 1
			    });
			},
			async getConfinedSpaceDetail(){
				const res=await getConfinedSpaceDetail({id:this.id})
				if(res.data.code==200){
					this.dailyData=res.data.result
					// this.imgList=this.obj.picUrl?.split(',')||[]
				      }
			},
			disallowedFn(){
				if(!this.approvalComments){
					 uni.showToast({
					 	title: '请输入审批意见',
					 	icon: 'error',
					 });
					 return;
				 }
				this.editSpaceWork(4)
			},
			approveFn(){
				this.approvalComments='同意'
				this.editSpaceWork(2)
			},
			async editSpaceWork(status) {
			  const res = await editSpaceWork({
			    id:this.dailyData.id,
				status,
				approvalComments:this.approvalComments
			  })
			  if (res.data.code == 200) {
			    uni.showToast({
			      title: res.message
			    })
			    uni.navigateTo({
			    	url: '/subpack_YunWei/yxkjzy/index'
			    })
			  } else {
			    uni.showToast({
			      title: res.data.message,
			      icon: 'none'
			    })
			  }
			},
			previewWechat(urlPdf) {
				console.log('11.333333333333',urlPdf);
				uni.showLoading({
					title: '正在加载中..'
				})
				uni.downloadFile({
					url: urlPdf,
					success: function(res) {
						var filePath = res.tempFilePath;
						uni.openDocument({
							filePath: filePath,
							showMenu: true,
							success: function(res) {
								console.log('打开文档成功');
								uni.hideLoading()
							},
						});
					},
					complete: function(r) {
						uni.hideLoading()
					}
				});
			},
			// 图片预览功能
			clickImg(url, index) {
			  var imageArr = [];
			  imageArr.push(url);
			  //uniapp预览轮播图方法
			  uni.previewImage({
			    current: index, //预览图片的下标
			    urls: imageArr //预览图片的地址，必须要数组形式
			  })
			},
		},
	};
</script>
<style scoped lang="scss">
.page-view {
  height: 100vh;
  // background: #f8f9fb;
  position: relative;
  overflow: hidden;
}
.top-bg{
	width: 100%;
	height: 330rpx;
	background: #2769F7;
	border-radius: 0rpx 0rpx 140rpx 140rpx;
	padding-top: 104rpx;
	text-align: center;
	font-weight: 600;
	font-size: 40rpx;
	color: #FFFFFF;
	letter-spacing: 4rpx;
	position: relative;
	.return{
		position: absolute;
		left: 32rpx;
		margin-top: 8rpx;
	}
}
.scroll-Y {
  height: 100%;
}
.posBox{
	position: absolute;
	top: 200rpx;
}
	.uni-body {	
		width: 629rpx;
		margin: 0 0 16rpx 32rpx;
		padding: 0 28rpx 28rpx 28rpx;
		background: #FFFFFF;
		font-weight: 800;
		font-size: 28rpx;
		color: #4A4A4A;
		border-radius: 10rpx;
		.flexItem {
			display: flex;
			border-top: 1rpx #EBEBEB solid;
			margin-bottom: 20rpx;
			padding-top: 20rpx;
			color: #989898;

			.text {
				color: #4A4A4A;
				flex: 1;
			}
			.text2 {
				color: #4A4A4A;
				width: 34%;
			}
			.textName{
				width: 34%;
			}
		}
 .note-red{
		  font-weight: 400;
		  color: #FF0200;
		  margin-top: 10rpx;
		  display: flex;
		  align-items: center;
		  margin-bottom: 14rpx;
		  .img{
			  width: 30rpx;
			  height: 30rpx;
			  margin-right: 16rpx;
		  }
	  }
	  .title {
	  	margin:20rpx 0;
	  	display: flex;
	  	align-items: center;
	  	font-size: 30rpx;
	  	.line-left {
	  		width: 8rpx;
	  		height: 20rpx;
	  		background: #2769F7;
	  		border-radius: 6rpx 6rpx 6rpx 6rpx;
	  		opacity: 0.6;
	  		margin-right: 12rpx;
	  	}
	  }
	}
	.info-row {
	  color:#989898;
	  display: flex;
	  padding-top: 26rpx;
	  text {
	    width: 35%;
	    color: #989898;
	    display: inline-block;
	  }
	}
	.btnBox{
		width: 96%;
		display: flex;
		font-weight: bold;
		font-size: 28rpx;
		margin-top: 36rpx;
		margin-left: 28rpx;
	.btn-item {
	  width: 50%;
	  height: 76rpx;
	  text-align: center;
	  line-height: 76rpx;
	  background: #E6EEFF;
	  color: #2769F7;
	  cursor: pointer;
	}	
	}
	/deep/ .u-textarea {
			width: 444rpx;
			height: 148rpx;
			background-color: #F2F6F7 !important;
			border-radius: 10rpx;
		}
		/deep/ .u-textarea__field {
		font-weight: 400;
		 color: #4a4a4a !important;
		  font-size: 24rpx !important;
		}
</style>